﻿@model Product
@{
    ViewBag.Title = "Index";
}

<h2>Product Manager</h2>

<div role="tabpanel">

    <!-- Nav tabs -->
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a href="#edit" aria-controls="edit" role="tab" data-toggle="tab">Product Edition</a></li>
        <li role="presentation"><a href="#list" aria-controls="list" role="tab" data-toggle="tab">List of Products</a></li>
    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="edit">
            <h4>@Html.ValidationSummary()</h4>
            @using (Html.BeginForm("Index", "Product",
    FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.HiddenFor(s => s.Id)
    <div class="row">
        <div class="form-group col-md-4">
            <div>Name</div>
            @Html.TextBoxFor(s => s.Name, new { @class = "form-control" })
        </div>

        <div class="form-group col-md-4">
            <div>Unit Price</div>
            @Html.TextBoxFor(s => s.UnitPrice, new { @class = "form-control" })
        </div>

        <div class="form-group col-md-4">
            <div>Unit Brief</div>
            @Html.TextBoxFor(s => s.UnitBrief, new { @class = "form-control" })
        </div>
    </div>
                
    <div class="row">
        <div class="form-group col-md-4">
            <div>Quantity</div>
            @Html.TextBoxFor(s => s.Quantity, new { @class = "form-control" })
        </div>

        <div class="form-group col-md-4">
            <div>Discount</div>
            @Html.TextBoxFor(s => s.Discount, new { @class = "form-control" })
        </div>

        <div class="form-group col-md-4">
            <div>Product Date</div>
            @Html.TextBoxFor(s => s.ProductDate, "{0:MM/dd/yyyy}", new { @class = "form-control datepicker" })
        </div>
    </div>
                
    <div class="row">
        <div class="form-group col-md-4">
            <div>Latest</div>
            @Html.CheckBoxFor(s => s.Latest)
        </div>

        <div class="form-group col-md-4">
            <div>Special</div>
            @Html.CheckBoxFor(s => s.Special)
        </div>

        <div class="form-group col-md-4">
            <div>Available</div>
            @Html.CheckBoxFor(s => s.Available)
        </div>
    </div>
                
    <div class="row">
        <div class="form-group col-md-4">
            <div>Image</div>
            <input type="file" name="UpImage" />
            @Html.HiddenFor(s => s.Image)
        </div>

        <div class="form-group col-md-4">
            <div>Category</div>
            @Html.DropDownList("CategoryId", null, new { @class = "form-control" })
        </div>

        <div class="form-group col-md-4">
            <div>Supplier</div>
            @Html.DropDownList("SupplierId", null, new {@class="form-control"})
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-12">
            <div>Description</div>
            @Html.TextAreaFor(s => s.Description, new { rows = 5, @class="form-control" })
        </div>
    </div>

    <div class="row">
        <div class="form-group col-md-12">
            <div></div>
            <div>
                <button onclick="form.action='/Adm/Product/Insert'" class="btn btn-default">Insert</button>
                @if (Model.Id != 0)
                {
                    <button onclick="form.action='/Adm/Product/Update'" class="btn btn-default">Update</button>
                    <a href="/Adm/Product/Delete/@Model.Id" class="btn btn-default">Delete</a>
                }
                <a href="/Adm/Product/Index" class="btn btn-default">Reset</a>
            </div>
        </div>
    </div>
}
        </div>
        <div role="tabpanel" class="tab-pane" id="list">
            <table class="table">
                <tr>
                    <th>Id</th>
                    <th>Name</th>
                    <th>Unit Price</th>
                    <th>Unit Brief</th>
                    <th>Quantity</th>
                    <th>Discount</th>
                    <th>Category</th>
                    <th>Supplier</th>
                    <th></th>
                </tr>
                @foreach (Product s in ViewBag.Products)
                {
                    <tr>
                        <td>@s.Id</td>
                        <td>@s.Name</td>
                        <td>@s.UnitPrice</td>
                        <td>@s.Quantity</td>
                        <td>@s.Discount</td>
                        <td>@s.UnitBrief</td>
                        <td>@s.Category.Name</td>
                        <td>@s.Supplier.Name</td>
                        <th>
                            <a href="/Adm/Product/Edit/@s.Id"
                               class="btn btn-default">Edit</a>
                        </th>
                    </tr>
                }
            </table>
        </div>
    </div>

</div>



@section scripts{
<script>
$(function () {
    $("input.datepicker").datepicker();
});
</script>
}